﻿using Microsoft.AspNetCore.Mvc.ModelBinding; 
using System.Text;

namespace MyCommon.MVC
{
    public static class ModelStateExtensions
    {
        public static string AllError(this ModelStateDictionary modelState)
        {
            StringBuilder str = new StringBuilder(); 

            foreach (var item in modelState)
            {
                if (item.Value.Errors != null)
                {
                    var msg = item.Value.Errors[0].ErrorMessage;
                    str.Append(msg + "\r\n");
                }
            }
            return str.ToString();
        }
    }
}
